From 7904cd04b997aa4b933a88763c39bd4be97e0b5f Mon Sep 17 00:00:00 2001 From: Alastair Tse Date: Thu, 5 Oct 2006 17:29:19 +0100 Subject: [PATCH] [XEND] Make SXP be compatible with sequencetypes (Tuples and Lists) Signed-off-by: Alastair Tse --- tools/python/xen/xend/sxp.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/python/xen/xend/sxp.py b/tools/python/xen/xend/sxp.py index 9cc8fc9731..af7cb9c0c2 100644 --- a/tools/python/xen/xend/sxp.py +++ b/tools/python/xen/xend/sxp.py @@ -378,7 +378,7 @@ def atomp(sxpr): def show(sxpr, out=sys.stdout): """Print an sxpr in bracketed (lisp-style) syntax. """ - if isinstance(sxpr, types.ListType): + if isinstance(sxpr, (types.ListType, types.TupleType)): out.write(k_list_open) i = 0 for x in sxpr: @@ -396,7 +396,7 @@ def show(sxpr, out=sys.stdout): def show_xml(sxpr, out=sys.stdout): """Print an sxpr in XML syntax. """ - if isinstance(sxpr, types.ListType): + if isinstance(sxpr, (types.ListType, types.TupleType)): element = name(sxpr) out.write('<%s' % element) for attr in attributes(sxpr): @@ -419,7 +419,7 @@ def elementp(sxpr, elt=None): sxpr sxpr elt element type """ - return (isinstance(sxpr, types.ListType) + return (isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) and (None == elt or sxpr[0] == elt)) @@ -435,7 +435,7 @@ def name(sxpr): val = None if isinstance(sxpr, types.StringType): val = sxpr - elif isinstance(sxpr, types.ListType) and len(sxpr): + elif isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr): val = sxpr[0] return val @@ -447,7 +447,7 @@ def attributes(sxpr): returns attribute list """ val = [] - if isinstance(sxpr, types.ListType) and len(sxpr) > 1: + if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1: attr = sxpr[1] if elementp(attr, k_attr_open): val = attr[1:] @@ -477,7 +477,7 @@ def children(sxpr, elt=None): returns children (filtered by elt if specified) """ val = [] - if isinstance(sxpr, types.ListType) and len(sxpr) > 1: + if isinstance(sxpr, (types.ListType, types.TupleType)) and len(sxpr) > 1: i = 1 x = sxpr[i] if elementp(x, k_attr_open): @@ -566,7 +566,7 @@ def with_id(sxpr, id, val=None): return s-exp or val """ - if isinstance(sxpr, types.ListType): + if isinstance(sxpr, (types.ListType, types.TupleType)): for n in sxpr: if has_id(n, id): val = n @@ -586,7 +586,7 @@ def child_with_id(sxpr, id, val=None): return s-exp or val """ - if isinstance(sxpr, types.ListType): + if isinstance(sxpr, (types.ListType, types.TupleType)): for n in sxpr: if has_id(n, id): val = n @@ -608,7 +608,7 @@ def elements(sxpr, ctxt=None): yield (sxpr, ctxt) i = 0 for n in children(sxpr): - if isinstance(n, types.ListType): + if isinstance(n, (types.ListType, types.TupleType)): # Calling elements() recursively does not generate recursively, # it just returns a generator object. So we must iterate over it. for v in elements(n, (i, sxpr, ctxt)): -- 2.30.2